<?=view('header.html')?>

<body class="layui-view-body bgwhite">
    <div class="layui-contents">
        <div class="layui-row">
            <div class="layui-cards" style="padding: 20px 0 0 0;">

                <form class="layui-form mokui-form" method="post" name="myform" id="myform">
                    <div class="layui-form-item">
                        <label class="layui-form-label">角色名称：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="data[name]" id="ams_name" value="<?=isset($data['name']) ? $data['name'] : ''?>" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">提交保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?=view('footer.html')?>
    <script type="text/javascript">
        layui.use(['layer', 'form', 'jquery'], function () {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
            

            form.on('submit(add)', function (data) {
                $.post(adminpath + 'admin/rbac/roleAdd', data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layui.table.reload('listTable');
                            // parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg, { icon: 5, time: 2000, anim: 6 });
                    }
                }, 'json')
            });

            form.on('submit(submit)', function (data) {
                var url = window.location.href;
                $.post(url, data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layui.table.reload('listTable');
                            // parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg, { icon: 5, time: 2000, anim: 6 });
                    }
                }, 'json')
            });


            form.on('submit(edit)', function (data) {
                var id = "{$id}";
                $.post(adminpath + 'admin/rbac/roleAdd?id=' + id, data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layui.table.reload('listTable');
                            // parent.location.reload();
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                }, 'json')
            });

        });
    </script>


</body>

</html>
